import {List} from "antd-mobile";
import React, {useEffect, useState} from "react";
import {useLocation, useNavigate} from "react-router-dom";
import {airConditionInfo, batteryInfo, DashboardData, repairInfo} from "../../../Datasource";
import {
    Form,
    Input,
    Button,
    Dialog,
    TextArea,
    DatePicker,
    Selector,
    Slider,
    Stepper,
    Switch,
} from 'antd-mobile'

const FaultEdit = () => {
    const location = useLocation()
    const navigate = useNavigate()
    const [initialValues, setInitialValues] = useState<any>({})
    const temp = location.pathname.split('/')
    const typeId = Number(temp[temp.length - 2])
    const deviceId = Number(temp[temp.length - 1])

    useEffect(() => {
        if (location) {
            repairInfo.map(e => {
                if (typeId === 1) {
                    airConditionInfo.map(a => {
                        if (a.id === deviceId) {
                            const faultItem = {
                                ...e,
                                device: a
                            }
                            setInitialValues(faultItem)
                        }
                    })
                } else if (typeId === 0) {
                    batteryInfo.map(a => {
                        if (a.id === deviceId) {
                            const faultItem = {
                                ...e,
                                device: a
                            }
                            setInitialValues(faultItem)
                        }
                    })
                }
            })
        }
    }, [])

    console.log(initialValues)

    if (initialValues.device) {
        return <Form initialValues={initialValues}
                     layout='horizontal' mode='card'
                     footer={
                         <Button block type='submit' color='primary' size='large' onClick={() => {
                             navigate('/')
                         }}>
                             提交
                         </Button>
                     }>
            <Form.Item name={['device', 'name']} label='设备名称'>
                <Input placeholder='请输入'/>
            </Form.Item>
            <Form.Item name={['device', 'machineRoom']} label='机房名称'>
                <Input placeholder='请输入'/>
            </Form.Item>
            <Form.Item name='type' label='设备类型'>
                <Input placeholder='请输入'/>
            </Form.Item>

            <Form.Item name='describe' label='基本问题描述'>
                <Input placeholder='请输入'/>
            </Form.Item>
            <Form.Item name='maintenancePerson' label='报修人姓名'>
                <Input placeholder='请输入'/>
            </Form.Item>
            <Form.Item name='contact' label='联系方式'>
                <Input placeholder='请输入'/>
            </Form.Item>
        </Form>
    } else {
        return null
    }
}

export default FaultEdit
